home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_a9x / ex4.ada < prev    next >
Text File  |  1996-01-30  |  2KB  |  81 lines

  1. PRAGMA LIST(On);
  2.  
  3. -- Source Ex4.Ada
  4. -- By Arthur V. Lopes, 7/12/94
  5.  
  6. -- This program implements a solution for the problem exibited
  7. -- by the program Concurrent_Programming_2.
  8.  
  9. -- Task entries are used to achieve syncronization between the
  10. -- tasks. The main task will make use of a start bottom to tell
  11. -- its children tasks that they can start displaing on the screen.
  12. -- Each children task will wait for its bottom to be pressed.
  13. -- After this is performed the main task will use a stop bottom
  14. -- to know that the children tasks are done. This is one way
  15. -- of achiving the goal of clearing the screen, running the two
  16. -- declared tasks concurrently, and then placing the cursor
  17. -- at the third line. 
  18.  
  19. WITH ADa.Text_IO, VT100; USE Ada.Text_IO;
  20. PROCEDURE Concurrent_Programming_3 IS
  21.  
  22.     PROTECTED Screen IS
  23.         PROCEDURE ClearScreen;
  24.         PROCEDURE Display_At(Column, Row : Integer; C : Character);
  25.     END Screen;
  26.  
  27.     PROTECTED BODY Screen IS
  28.  
  29.         PROCEDURE ClearScreen IS
  30.         BEGIN
  31.             VT100.ClearScreen;
  32.         END ClearScreen;
  33.  
  34.         PROCEDURE Display_At(Column, Row : Integer; C : Character) IS
  35.  
  36.         BEGIN
  37.             VT100.MoveCursor(Column,Row);
  38.             Put(C);
  39.         END Display_At;  
  40.     END Screen;
  41.  
  42.     SUBTYPE Interval IS INTEGER RANGE 1 .. 10;
  43.  
  44.     TASK Display_A IS
  45.         ENTRY Start;
  46.         ENTRY Stop;
  47.     END Display_A;
  48.  
  49.     TASK Display_B IS
  50.         ENTRY Start;
  51.         ENTRY Stop;
  52.     END Display_B;
  53.  
  54.     TASK BODY Display_A IS -- This is the body part of Display_A
  55.     BEGIN
  56.         ACCEPT Start;
  57.         FOR I IN Interval LOOP
  58.             Display_At(I,1,'A');
  59.             DELAY 0.01;
  60.         END LOOP;
  61.         ACCEPT Stop;
  62.     END Display_A;
  63.  
  64.     TASK BODY Display_B IS
  65.     BEGIN
  66.         ACCEPT Start;
  67.         FOR I IN Interval LOOP
  68.             Display_At(I,2,'B');
  69.             DELAY 0.01;
  70.         END LOOP;
  71.         ACCEPT Stop;
  72.     END Display_B;
  73.  
  74. BEGIN
  75.     ClearScreen;
  76.     Display_A.Start;
  77.     Display_B.Start;
  78.     Display_A.Stop;
  79.     Display_B.Stop;
  80.     New_Line;
  81. END Concurrent_Programming_3;